@import '@/assets/styles/_mixins.less';

.umo-editor-content {
  accent-color: var(--umo-primary-color);
  &.show-line-number {
    .umo-editor {
      > *:not([data-line-number='false']):not(div) {
        position: relative;

        &::before {
          position: absolute;
          content: counter(title) '.';
          counter-increment: title;
          right: 100%;
          margin-right: 20px;
          color: var(--umo-content-line-number-color);
          font-family: var(--umo-font-family);
          font-size: 14px;
          font-weight: 400;
        }
      }
    }
  }

  &.format-painter {
    cursor: url('@/assets/images/format-painter.svg'), text;
  }

  &:not(.show-bookmark) {
    .umo-editor-bookmark {
      display: none;
    }
  }

  .umo-editor {
    outline: none;
    counter-reset: title;
    color: var(--umo-content-text-color);
    width: 100%;
    padding: 0 var(--umo-page-margin-right) 0 var(--umo-page-margin-left);
    box-sizing: border-box;
    word-wrap: break-word;
    white-space: break-spaces;
    -webkit-font-variant-ligatures: none;
    font-variant-ligatures: none;
    font-feature-settings: 'liga' 0;
    min-height: calc(
      var(--umo-page-height) - var(--umo-page-margin-top) -
        var(--umo-page-margin-bottom)
    );
    float: left;
    font-family: var(--umo-font-family);
    font-size: var(--umo-font-size);
    > * {
      position: relative;
      z-index: 1;

      + *:not(.umo-floating-node) {
        margin-top: var(--umo-content-node-bottom);
      }

      &.umo-node-focused,
      &.ProseMirror-selectednoderange {
        @media screen {
          &:not(.is-editor-empty):not(hr):not(.tableWrapper):not(
              .umo-page-break
            ):not(table):not(.umo-code-block):not(.umo-floating-node):before {
            content: '';
            display: block;
            position: absolute;
            left: -8px;
            top: -5px;
            right: -8px;
            bottom: -5px;
            border-radius: var(--umo-radius);
            background: var(--umo-content-node-selected-background);
            pointer-events: none;
            z-index: -1;
          }
          &.umo-floating-node {
            outline: solid 1px var(--umo-primary-color);
            transform: translateY(
              calc(var(--umo-content-node-bottom) / 2 - 1px)
            );
            & > * {
              transform: translateY(
                calc(-1 * (var(--umo-content-node-bottom) / 2 - 1px))
              );
            }
          }
        }
        &.umo-page-divider {
          border-radius: var(--umo-radius);
          background: var(--umo-content-node-selected-background);
          margin-left: -8px;
          margin-right: -8px;
          padding-left: 8px;
          padding-right: 8px;
        }
        &.umo-page-break {
          background-color: var(--umo-primary-color);
          color: var(--umo-primary-color);
          &::after {
            border-color: var(--umo-primary-color);
          }
        }

        .umo-select-outline {
          outline: solid 1px var(--umo-primary-color);
        }
      }
    }
  }

  &.is-empty
    .is-editor-empty:not(.umo-node-view):not(.tableWrapper):not(
      .column-block
    ):not(ul):not(ol) {
    &::after {
      display: inline-block;
      vertical-align: text-top;
      line-height: 1;
    }
    &:first-child {
      > *:not(table) {
        display: none;
      }

      &::after {
        color: var(--umo-content-placeholder-color);
        content: attr(data-placeholder);
        pointer-events: none;
      }
    }
  }

  @media screen {
    &:not(.is-readonly) .umo-text-selection {
      background-color: var(--umo-text-selection-background);
    }

    &.show-model .umo-text-selection {
      background-color: var(--umo-text-selection-background);
    }

    ::selection {
      background-color: var(--umo-text-selection-background);
    }
  }

  a {
    color: var(--umo-primary-color);
    text-decoration: none;
    cursor: pointer;

    &:hover {
      opacity: 0.8;
      text-decoration: underline;
    }
  }

  code {
    color: var(--umo-content-code-color);
    background-color: var(--umo-content-code-background);
    font-family: var(--umo-content-code-family);
    border-radius: 3px;
    padding: 0.1em 0.4em;
    margin-left: 0.25em;
    margin-right: 0.25em;
  }

  ul,
  ol {
    counter-reset: section;
    list-style-type: none;
    li {
      word-break: break-all;
      list-style-type: none;
      padding: 0.25em 0;
      > p:before {
        counter-increment: section;
        display: inline;
        margin-right: 0.5em;
      }
      ol,
      ul {
        margin-top: 0.25em;
        padding-left: 1.6em;
      }
    }
  }
  ol {
    &[type='decimal'] li > p:before {
      content: counters(section, '.') '. ';
    }
    &[type='decimal-leading-zero'] li > p:before {
      content: counters(section, '.', decimal-leading-zero) '.';
    }
    &[type='lower-roman'] li > p:before {
      content: counters(section, '.', lower-roman) '.';
    }
    &[type='upper-roman'] li > p:before {
      content: counters(section, '.', upper-roman) '.';
    }
    &[type='lower-latin'] li > p:before {
      content: counters(section, '.', lower-latin) '.';
    }
    &[type='upper-latin'] li > p:before {
      content: counters(section, '.', upper-latin) '.';
    }
    &[type='trad-chinese-informal'] li > p:before {
      content: counters(section, '.', trad-chinese-informal) '.';
    }
    &[type='simp-chinese-formal'] li > p:before {
      content: counters(section, '.', simp-chinese-formal) '.';
    }
  }
  ul {
    &[type='disc'] li > p:before {
      content: '•';
    }
    &[type='circle'] li > p:before {
      content: '◦';
    }
    &[type='square'] li > p:before {
      content: '▪';
    }
  }

  blockquote {
    border-left: 3px solid var(--umo-primary-color);
    padding: 0.5em 1em;
    color: #777;
    background-color: rgba(0, 0, 0, 0.03);
    margin: 0;
  }

  table {
    border-collapse: collapse;
    table-layout: fixed;
    width: 100%;
    margin: 0;
    overflow: hidden;
    page-break-inside: auto;
    margin-left: auto;
    margin-right: auto;
    tr {
      page-break-inside: avoid;
      page-break-after: auto;
    }

    // thead {
    //   display: table-header-group;
    // }
    td,
    th {
      min-width: 1em;
      border: 1px solid var(--umo-content-table-border-color);
      padding: 3px 5px;
      vertical-align: middle;
      box-sizing: border-box;
      position: relative;

      > * {
        margin-bottom: 0;
      }

      &[align='left-top'] {
        vertical-align: top;
        text-align: left;
      }

      &[align='center-top'] {
        vertical-align: top;
        text-align: center;
      }

      &[align='right-top'] {
        vertical-align: middle;
        text-align: right;
      }

      &[align='justify-top'] {
        vertical-align: middle;
        text-align: justify;
      }

      &[align='left-middle'] {
        vertical-align: middle;
        text-align: left;
      }

      &[align='center-middle'] {
        vertical-align: middle;
        text-align: center;
      }

      &[align='right-middle'] {
        vertical-align: middle;
        text-align: right;
      }

      &[align='justify-middle'] {
        vertical-align: middle;
        text-align: justify;
      }

      &[align='left-bottom'] {
        vertical-align: bottom;
        text-align: left;
      }

      &[align='center-bottom'] {
        vertical-align: middle;
        text-align: center;
      }

      &[align='right-bottom'] {
        vertical-align: bottom;
        text-align: right;
      }

      &[align='justify-bottom'] {
        vertical-align: bottom;
        text-align: justify;
      }
    }

    th {
      font-weight: bold;
      text-align: left;
      background-color: var(--umo-content-table-thead-background);
    }

    .selectedCell:after {
      z-index: 2;
      position: absolute;
      content: '';
      left: 0;
      right: 0;
      top: 0;
      bottom: 0;
      background: var(--umo-content-table-selected-background);
      pointer-events: none;
    }

    .column-resize-handle {
      position: absolute;
      right: -1px;
      top: 0;
      bottom: -1px;
      width: 3px;
      background-color: var(--umo-primary-color);
      pointer-events: none;
    }

    p {
      margin: 0;
    }
  }

  .indent-1 {
    text-indent: 2em;
  }

  .indent-2 {
    text-indent: 4em;
  }

  .indent-3 {
    text-indent: 6em;
  }

  .indent-4 {
    text-indent: 8em;
  }

  .indent-5 {
    text-indent: 10em;
  }

  .tableWrapper {
    max-width: 100%;
    overflow-x: auto;
    .umo-scrollbar();
  }

  .resize-cursor {
    cursor: col-resize;
  }

  .umo-task-list {
    list-style: none;
    padding: 0;

    li {
      display: flex;

      &[data-checked='true'] {
        p {
          opacity: 0.5;
          text-decoration: line-through;

          &:has([style]) {
            text-decoration: inherit;
          }

          * {
            text-decoration: line-through;
          }
        }
        input[type='checkbox'] {
          background-color: var(--umo-primary-color);
          border: none;
          &::after {
            content: '';
            width: 16px;
            height: 16px;
            background: url('')
              0 1px;
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
          }
        }
      }

      > label {
        flex: 0 0 auto;
        margin-right: 10px;
        user-select: none;
      }

      > div {
        flex: 1 1 auto;
      }
    }

    input[type='checkbox'] {
      appearance: none;
      cursor: pointer;
      width: 16px;
      height: 16px;
      padding: 0.1em 0.4em;
      opacity: 0.6;
      border: 1px solid var(--umo-text-color);
      border-radius: 2px;
      background-color: white;
      position: relative;
      color: #fff;
      &:hover {
        border-color: var(--umo-primary-color);
      }
    }
  }

  .umo-search-result {
    background-color: var(--umo-content-search-result-background);

    &-current {
      background: var(--umo-content-search-result-current-background);
    }
  }

  .umo-page-divider {
    .umo-page-divider();
  }

  .umo-page-break {
    display: block;
    width: 100%;
    height: 1px;
    background: var(--umo-content-node-border);
    break-before: page;
    margin-top: 30px;
    margin-bottom: 30px;
    position: relative;
    &::after {
      content: attr(data-content);
      font-size: 10px;
      border: solid 1px var(--umo-content-node-border);
      padding: 1px 8px;
      border-radius: 2px;
      background-color: var(--umo-color-white);
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);
    }
    @media print {
      height: 0;
      margin-top: 0;
      margin-bottom: 0;
      page-break-before: always;
      &::after {
        display: none;
      }
    }
  }

  .umo-node-view {
    display: flex;
    position: relative;
    max-height: 100%;
    .umo-node-container {
      max-height: 100%;
    }
    .umo-hover-shadow:hover {
      box-shadow: var(--umo-shadow);
    }
  }

  // 插件样式
  .ProseMirror-gapcursor {
    height: 24px;
    display: flex;
    &:after {
      width: 16px;
      height: 2px;
      margin-top: 18px;
      background-color: var(--umo-primary-color);
    }
  }

  .Tiptap-invisible-character {
    text-indent: 0;
    &--break::before {
      content: '↓';
      color: var(--umo-content-invisible-break-color);
    }
    &--paragraph::before {
      content: '↵';
      color: var(--umo-content-invisible-break-color);
    }
    @media print {
      display: none;
    }
  }

  .Tiptap-mathematics {
    &-editor {
      background: var(--umo-content-node-selected-background);
      font-family: monospace;
      padding: 0.2em 0.5em;
      // outline: solid 1px var(--umo-primary-color);
    }

    &-render {
      cursor: pointer;
      padding: 0 0.25em;
      transition: background 0.2s;

      &:hover {
        background: var(--umo-content-node-selected-background);
      }
    }

    &-editor,
    &-render {
      border-radius: 0.2em;
      display: inline-block;
    }
  }

  .umo-color-highlighter {
    white-space: nowrap;

    &::before {
      background-color: var(--color);
      border: 1px solid rgba(128, 128, 128, 0.3);
      border-radius: 2px;
      content: ' ';
      display: inline-block;
      height: 1em;
      margin-bottom: 0.15em;
      margin-right: 0.1em;
      vertical-align: middle;
      width: 1em;
    }
  }

  .column-block {
    width: 100%;
    display: grid;
    grid-auto-flow: column;
    gap: 12px;
  }

  .column {
    overflow: auto;
    background-color: var(--umo-content-table-selected-background);
    border-radius: var(--umo-radius);
    padding: 8px 12px;
    &.umo-node-focused {
      outline: 2px dashed var(--umo-primary-color);
    }
  }
  h1 {
    font-size: 2.5em;
  }
  h2 {
    font-size: 2em;
  }
  h3 {
    font-size: 1.5em;
  }
  h4 {
    font-size: 1.25em;
  }
  h5 {
    font-size: 1em;
  }
  h6 {
    font-size: 0.85em;
  }
}
.umo-editor-bookmark {
  color: hsl(0, 1%, 68%);
  @media print {
    display: none;
  }
}

.umo-editor-bookmark::after {
  content: '}';
}

.umo-editor-bookmark::before {
  content: '{';
}

:-webkit-any(article, aside, nav, section) {
  .umo-editor {
    h1 {
      font-size: 2.5em;
    }
    h2 {
      font-size: 2em;
    }
    h3 {
      font-size: 1.5em;
    }
    h4 {
      font-size: 1.25em;
    }
    h5 {
      font-size: 1em;
    }
    h6 {
      font-size: 0.85em;
    }
  }
}
